package core;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import javax.imageio.ImageIO;

public abstract class FlyingObject implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6158722080762151757L;
	protected int x;
	protected int y;
	protected int width;
	protected int height;
	protected int speed;
	protected int live=0;
	protected int dead=1;
	protected int remove=2;
	protected int status=live;
	protected int index=0;
	public abstract void step();
	public abstract void paintImage(Graphics g);
	public void step2(int x,int y) {
		
	}
	public FlyingObject() {
		super();
	}
	public FlyingObject(int width, int height) {
		super();
		this.width = width;
		this.height = height;
		this.x = (int)(Math.random()*(World.WORLD_WIDTH-width));
		this.y = -height;
	}

	public FlyingObject(int x, int y, int width, int height) {
		super();
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
	public static BufferedImage readImage(String fileName) {	
		try {
			BufferedImage img = ImageIO.read(new File(fileName));
			return img;
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public boolean isLife() {
		return status == live;
	}
	public boolean isDead() {
		return status == dead;
	}
	public boolean isRemove() {
		return status == remove;
	}
	public void goDead() {//去死
		status=dead;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public int getRemove() {
		return remove;
	}
	public void setRemove(int remove) {
		this.remove = remove;
	}
	public int getSpeed() {
		return speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	@Override
	public String toString() {
		return "FlyingObject [x=" + x + ", y=" + y + ", status=" + status + "]";
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getLive() {
		return live;
	}
	public void setLive(int live) {
		this.live = live;
	}
	public int getDead() {
		return dead;
	}
	public void setDead(int dead) {
		this.dead = dead;
	}
	public int getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public void indexAddOne() {
		index++;
	}
	public boolean outOfBounds() {
		if(this.y>World.WORLD_HEIGHT) {
			return true;
		}
		return false;
	}	
}
